inspector: Do a better job with readonly properties
authorMatthias Clasen <mclasen@redhat.com>
Thu, 10 Mar 2016 02:42:08 +0000 (21:42 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 10 Mar 2016 02:59:43 +0000 (21:59 -0500)
Say if they are non-writable or construct-only, and also
gray out construct-only properties in the list.

gtk/inspector/prop-editor.c
gtk/inspector/prop-list.c

index 1f1bca896d5386fdbf715e8b03a3d36cc8a746a3..03debe0344bbfa78c5060ac75d44242128b4ef99 100644 (file)
@@ -1712,6 +1712,20 @@ constructed (GObject *object)
   can_modify = ((spec->flags & G_PARAM_WRITABLE) != 0 &&
                 (spec->flags & G_PARAM_CONSTRUCT_ONLY) == 0);
 
+  if ((spec->flags & G_PARAM_CONSTRUCT_ONLY) != 0)
+    label = gtk_label_new ("(construct-only)");
+  else if ((spec->flags & G_PARAM_WRITABLE) == 0)
+    label = gtk_label_new ("(not writable)");
+  else
+    label = NULL;
+
+  if (label)
+    {
+      gtk_widget_show (label);
+      gtk_style_context_add_class (gtk_widget_get_style_context (label), GTK_STYLE_CLASS_DIM_LABEL);
+      gtk_container_add (GTK_CONTAINER (editor), label);
+    }
+
   /* By reaching this, we already know the property is readable.
    * Since all we can do for a GObject is dive down into it's properties
    * and inspect bindings and such, pretend to be mutable.
index c02ba56ef61c982f94bf5a90a7d7acbd0d9ba4b3..e94644429d02ca39fc2a631b35dff7b04660dcf3 100644 (file)
@@ -412,6 +412,7 @@ gtk_inspector_prop_list_update_prop (GtkInspectorPropList *pl,
   gchar *value;
   gchar *type;
   gchar *attribute = NULL;
+  gboolean writable;
 
   g_value_init (&gvalue, prop->value_type);
   if (pl->priv->child_properties)
@@ -447,13 +448,16 @@ gtk_inspector_prop_list_update_prop (GtkInspectorPropList *pl,
          attribute = g_strdup_printf ("%d", column);
     }
 
+  writable = ((prop->flags & G_PARAM_WRITABLE) != 0) &&
+             ((prop->flags & G_PARAM_CONSTRUCT_ONLY) == 0);
+
   gtk_list_store_set (pl->priv->model, iter,
                       COLUMN_NAME, prop->name,
                       COLUMN_VALUE, value ? value : "",
                       COLUMN_TYPE, type ? type : "",
                       COLUMN_DEFINED_AT, g_type_name (prop->owner_type),
                       COLUMN_TOOLTIP, g_param_spec_get_blurb (prop),
-                      COLUMN_WRITABLE, (prop->flags & G_PARAM_WRITABLE) != 0,
+                      COLUMN_WRITABLE, writable,
                       COLUMN_ATTRIBUTE, attribute ? attribute : "",
                       -1);